<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="/static/admin/font/iconfont/iconfont.css">
<link rel="stylesheet" type="text/css" href="/static/admin/plugins/Bootstrap/5.0.1/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/static/admin/style/style.css" />
</head>
<body>
<div class="main">
  <ol class="breadcrumb">
    <li class="breadcrumb-item iconfont icon-home">首页</li>
    <li class="breadcrumb-item active">管理员列表</li>
  </ol>
  <div class="list-info mt-3">
    <a class="btn btn-primary btn-sm" href="/admin/admin/create">创建</a>
    <span>共有 <strong>{{$admins->total()}}</strong> 条数据</span>
  </div>
  <table class="table table-bordered table-hover text-center mt-3">
    <thead>
      <tr>
      	<th>管理员ID</th>
        <th>账号</th>
        <th>创建时间</th>
        <th>状态</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
      @foreach($admins as $value)
      <tr>
      	<td>{{$value->id}}</td>
        <td>{{$value->username}}</td>
        <td>{{ Str::limit($value->created_at, 10, '') }}</td>
        <td>
          @if($value->status == 1)
          <span class="badge bg-success">开启</span>
          @else
          <span class="badge bg-danger">关闭</span>
          @endif
        </td>
        <td>
          <a class="btn btn-primary btn-sm" href="/admin/admin/edit?id={{$value->id}}">编辑</a>
          <a class="btn btn-danger btn-sm" href="javascript:void(0);" onclick="deleteAction({{$value->id}})">删除</a>
        </td>
      </tr>
      @endforeach
    </tbody>
  </table>
  <div class="page my-3">{{ $admins->appends(Request()->all())->render() }}</div>
</div>
<script type="text/javascript" src="/static/admin/plugins/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript" src="/static/admin/plugins/Bootstrap/5.0.1/js/bootstrap.js"></script>
<script type="text/javascript" src="/static/admin/plugins/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/admin/script/common.js"></script>
<script type="text/javascript">
function deleteAction(id = '')
{
  layer.confirm('确认删除？', function(index) {
    var load = layer.load();
    $.ajax({
      type: 'GET',
      url: '/admin/admin/delete?id=' + id,
      dataType: 'json',
      success: function(res) {
        layer.close(load);
        if (res.code == 200) {
          layer.msg('操作成功', {time: 1500}, function() {window.location.reload();});
        } else if (res.code == 400) {
          layer.msg(res.message);
        } else {
          layer.msg('操作失败');
        }
      }
    });     
  });
}    
</script>
</body>
</html>